import { computed, reactive, ref } from "vue";

export default function InitHook() {
	const searchForm = reactive<{
		keyword: string;
	}>({
		keyword: ""
	});
	const selectCity = ref<Base.CommonData>({
		id: 0,
		title: ""
	});
	const cityList = ref<Base.CommonData[]>([
		{
			id: 1,
			title: "北京市"
		},
		{
			id: 2,
			title: "上海市"
		},
		{
			id: 3,
			title: "广州市"
		},
		{
			id: 4,
			title: "深圳市"
		},
		{
			id: 5,
			title: "成都市"
		},
		{
			id: 6,
			title: "天津市"
		},
		{
			id: 7,
			title: "武汉市"
		},
		{
			id: 8,
			title: "南京市"
		},
		{
			id: 9,
			title: "杭州市"
		},
		{
			id: 10,
			title: "南京市"
		},
		{
			id: 11,
			title: "武汉市"
		},
		{
			id: 12,
			title: "成都市"
		},
		{
			id: 13,
			title: "天津市"
		},
		{
			id: 14,
			title: "杭州市"
		},
		{
			id: 15,
			title: "南京市"
		}
	]);
	const showList = computed<Base.CommonData[]>(() => {
		if (!searchForm.keyword) return cityList.value;
		return cityList.value.filter((item) => item.title.includes(searchForm.keyword));
	});
	return {
		searchForm,
		selectCity,
		cityList,
		showList
	};
}
